<?php

namespace App\Models\Archive;

use App\Models\Archive\Migration\OperationLogsTable;
use App\Models\Common\BaseMigration;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;

class OperationLog extends Model
{
    use UuidTrait;

    protected $connection = BaseMigration::DB_CONN;

    protected $appends = ['as_ip'];

    public static function getTableName($datetime = null): string
    {
        return OperationLogsTable::getTableName($datetime);
    }

    public function getAsIpAttribute(): string
    {
        if ($ip = $this->attributes['login_ip']) {
            return long2ip($ip) ?: '';
        } else {
            return '';
        }
    }
}
